import { defineStore } from 'pinia'
import { getmyData } from '../api/index'
import { getimgData } from '../api/index'
import { onlaytionData } from '../api/index'

export const usecurrentStore = defineStore('user', {
  state: () => ({
    getmuResults: [],
    myResults: [],
    listimg: [],
    imgResults: [],
    doctorId: JSON.parse(localStorage.getItem('doctorId')||''),
    sessionId: JSON.parse(localStorage.getItem('sessionId')||'')
  }),
  actions: {
    //我的资料
    async handmydata(doctorId: number, sessionId: number) {
      try {
        const my_list = await getmyData(doctorId, sessionId)
        console.log(my_list, 'my_list')
        this.$state.myResults = my_list.data.result
        console.log(this.$state.myResults, 'this.$state.myResults')
      } catch (error) {
        console.log('错误', error)
      }
    },
    async imgluist() {
      try {
        const aimg_list = await getimgData()
        // console.log(aimg_list, 'my_list')
        this.$state.listimg = aimg_list.data.result
        // console.log(this.$state.listimg, 'this.$state.imgResults')
      } catch (error) {
        console.log('错误ww', error)
      }
    },
    // 上传形象照
    async imgmydata(doctorId: number, sessionId: number, imagePic: File) {
      try {
        const img_list = await onlaytionData(doctorId, sessionId, imagePic)
        console.log(img_list, 'my_list')
        this.$state.imgResults = img_list.data.result
        console.log(this.$state.imgResults, 'this.$state.imgResults')
      } catch (error) {
        console.log('错误', error)
      }
    }
  }
})
